package com.ysm.kotlin.activity

import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.databinding.DataBindingUtil
import com.ysm.kotlin.R
import com.ysm.kotlin.databinding.ActivityMainBinding
import com.ysm.kotlin.viewmodel.MainViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch

class MainActivity : AppCompatActivity() , CoroutineScope by MainScope(){
    val TAG = "MainActivity"
    private lateinit var binding: ActivityMainBinding

    private val mViewModel : MainViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = DataBindingUtil.setContentView<ActivityMainBinding>(this,R.layout.activity_main)
        binding.viewmodel = mViewModel
        binding.lifecycleOwner = this //这个语句是必须的！

//        binding.tvKotlinCoroutine.text = "Jack"

        binding.btSubmit.setOnClickListener{
             mViewModel.getUserName()
        }

        mViewModel.userLiveData.observe(this){
            Log.e(TAG,"mViewModel ->>>>>>> ${it.toString()}")
        }
    }
}